package com.member.shop.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.member.common.utils.DateUtils;
import com.member.shop.domain.SysBizMaterial;
import com.member.shop.mapper.SysBizMaterialMapper;
import com.member.shop.service.ISysBizMaterialService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

/**
 * 素材Service业务层处理
 *
 * @author lixinchen
 * @date 2024-05-08
 */
@Service
public class SysBizMaterialServiceImpl extends ServiceImpl<SysBizMaterialMapper, SysBizMaterial> implements ISysBizMaterialService {
    @Resource
    private SysBizMaterialMapper sysBizMaterialMapper;

    /**
     * 查询素材
     *
     * @param id 素材主键
     * @return 素材
     */
    @Override
    public SysBizMaterial selectSysBizMaterialById(Long id) {
        return sysBizMaterialMapper.selectById(id);
    }

    /**
     * 查询素材列表
     *
     * @param sysBizMaterial 素材
     * @return 素材
     */
    @Override
    public List<SysBizMaterial> selectSysBizMaterialList(LambdaQueryWrapper<SysBizMaterial> queryWrapper) {
        return sysBizMaterialMapper.selectList(queryWrapper);
    }

    /**
     * 新增素材
     *
     * @param sysBizMaterial 素材
     * @return 结果
     */
    @Override
    public int insertSysBizMaterial(SysBizMaterial sysBizMaterial) {
        sysBizMaterial.setCreateTime(DateUtils.getNowDate());
        return sysBizMaterialMapper.insert(sysBizMaterial);
    }

    /**
     * 修改素材
     *
     * @param sysBizMaterial 素材
     * @return 结果
     */
    @Override
    public int updateSysBizMaterial(SysBizMaterial sysBizMaterial) {
        sysBizMaterial.setUpdateTime(DateUtils.getNowDate());
        return sysBizMaterialMapper.updateById(sysBizMaterial);
    }

    /**
     * 批量删除素材
     *
     * @param ids 需要删除的素材主键
     * @return 结果
     */
    @Override
    public int deleteSysBizMaterialByIds(Long[] ids) {
        return sysBizMaterialMapper.deleteBatchIds(Arrays.asList(ids));
    }

    /**
     * 删除素材信息
     *
     * @param id 素材主键
     * @return 结果
     */
    @Override
    public int deleteSysBizMaterialById(Long id) {
        return sysBizMaterialMapper.deleteById(id);
    }

    /**
     * 查询素材列表
     *
     * @param sysBizMaterial 素材
     * @return 素材集合
     */
    @Override
    public List<SysBizMaterial> selectSysBizMaterialList(SysBizMaterial sysBizMaterial) {
        return sysBizMaterialMapper.selectSysBizMaterialList(sysBizMaterial);
    }

    @Override
    public List<SysBizMaterial> queryCollectByMaterial(Long userId, Integer type) {
        return sysBizMaterialMapper.queryCollectByMaterial(userId, type);
    }
}
